/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view>
		<view class="container">
			<view class="message">
				<view>温馨提示：</view>
				<view>1.限时特价、预约资格等购买优惠可能一并取消</view>
				<view>2.如遇订单拆分、使用优惠券无法返还</view>
				<view>3.支付金额，抵扣余额积分都按原路退款</view>
				<view>4.订单一旦取消，无法恢复</view>
			</view>
			<form @submit="refundOrder" class="formbox">
				<view @tap="openReasonModal" class="item" data-id="0">
					<view class="item-name">退款原因:</view>
					<view class="item-input">{{reasonList[reasonSelect]}}</view>
					<view class="item-img">
						<image class="arrow" :src="imgUrl+'common/icon-arrowdown.png'" role="img"></image>
					</view>
				</view>
				<view class="item">
					<view class="item-name">联系人:</view>
					<input class="item-input" @input="changeName" name="consignee" :value="order.consignee"></input>
				</view>
				<view class="item">
					<view class="item-name">手机号码:</view>
					<input class="item-input" @input="changeTell" name="mobile" :value="order.mobile">
					</input>
				</view>
				<button class="submit-btn" form-type="submit" role="button" aria-disabled="false">申请退款</button>
			</form>
		</view>
		<!-- 取消订单原因弹框 -->
		<view v-if="ishide">
			<view class="cover-layer" @tap="closeReasonModal"></view>
			<view class="reason-modal">
				<!-- <icon type="cancel" color="gray" size="22" class="modal-close" @tap="closeReasonModal" /> -->
				<image :src="imgUrl+'common/close.png'" class="modal-close" @tap="closeReasonModal"></image>
				<view class="reason-nav">取消原因</view>
				<radio-group class="reason-list" @change="reasonChange">
					<label class="reason-item" v-for="(item,index) in reasonList" :key="index">
						<radio color="#ff3b3b"  :value="item ":checked="index==reasonSelect"/>
						{{item}}
					</label>
				</radio-group>
				<view class="reason-btn" @tap="closeReasonModal">确 定</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {putCancelOrder} from "@/api/api.js";
	import common from "@/common/common.js";
	import config from "@/api/config";
	export default {
		data() {
			return {
				order:{
					"consignee":"",
					"mobile":"",
					"order_id":"",
					"order_sn":""
				},
				imgUrl:config.imgUrl,
				reasonSelect: 0, //选择取消订单的原因
				reasonList: [
					'订单不能按预计时间送达', '操作有误(商品、地址等选错)', '重复下单/误下单',
					'其他渠道价格更低', '该商品降价了', '不想买了', '其他原因'
				],
				ishide:false,
			};
		},
		onLoad(options){
			console.log(options)
			this.order.consignee=options.consignee
			this.order.mobile=options.mobile
			this.order.order_id=options.orderId
			this.order.order_sn=options.order_sn
			
		},
		methods:{
			openReasonModal(){
				this.ishide=true
			},
			closeReasonModal(){
				this.ishide=false
			},
			reasonChange(e){
				console.log(e)
				let value=e.detail.value;
				this.reasonList.forEach((i,index)=>{
					if(i==value){
						console.log(index)
						this.reasonSelect=index
					}
				})
			},
			changeName(e){
				// console.log(e)
				this.order.consignee=e.detail.value
			},
			changeTel(e){
				this.order.mobile=e.detail.value
			},
			/*申请退款*/
			refundOrder(){
				let params=this.order;
				this.putCancelOrder(params)
			},
			putCancelOrder(params){
				putCancelOrder(params).then(res=>{
					let that=this;
					console.log(res)
					if(res.status==1){
						common.toast("success","已提交申请",2000)
						uni.showToast({
							icon:"success",
						    title: "已提交申请",
						    duration: 2000,
							complete: function () {
								setTimeout(()=>{
									uni.navigateTo({
										url:`/pages/user/order_detail/order_detail?order_sn=${that.order.order_sn}`
									})
								},3000)
							}
						})
					}else{
						common.toast("none",res.msg,2000)
					}
				})
			},
			jump(){
				uni.switchTab({
					url:"/pages/index/index"
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		font-size: 28rpx;
	}

	.message {
		padding: 60rpx 40rpx;
		line-height: 40rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		border-radius: 10rpx;
		background: #fff;
		width: 710rpx;
		box-sizing: border-box;
	}

	.item {
		float: left;
		padding: 0 30rpx;
		width: 100%;
		box-sizing: border-box;
		border-bottom: 1rpx solid #f3f3f3;
		background-color: white;
		line-height: 100rpx;
		height: 100rpx;
		position: relative;
	}

	.item-name {
		float: left;
	}

	.item-input {
		float: left;
		height: 100rpx;
		width: 450rpx;
		margin-left: 20rpx;
		word-break: keep-all;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.arrow {
		position: absolute;
		right: 30rpx;
		width: 32rpx;
		height: 32rpx;
		padding-top: 30rpx;
	}

	.submit-btn {
		position: fixed;
		bottom: 80rpx;
		width: 50%;
		margin-left: 25%;
		font-size: 36rpx;
		background-color: #ff3b3b;
		color: white;
		line-height: 100rpx;
		border-radius: 10rpx;
	}

	/* 取消订单原因弹框 */
	.reason-modal {
		z-index: 20;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		overflow-y: hidden;
		color: #666666;
		background-color: white;
	}

	.reason-nav {
		text-align: center;
		font-size: 35rpx;
		padding-top: 30rpx;
	}

	.reason-list {
		padding: 20rpx 30rpx 40rpx;
		font-size: 28rpx;
	}

	.reason-item {
		display: block;
		padding: 20rpx 0;
	}

	.reason-btn {
		width: 100%;
		color: white;
		background-color: #ff3b3b;
		line-height: 90rpx;
		text-align: center;
		font-size: 40rpx;
	}

	.formbox {
		border-radius: 10rpx;
		width: 710rpx;
		margin: 0 auto;
		overflow: hidden;
		margin-top: 20rpx;
	}
	.modal-close{
		width: 40rpx;
		height: 40rpx;
	}
</style>
